package pencarian;
import java.io.*;
import java.util.Scanner;
import java.util.ArrayList;

public class MapTranslator {
    //atribut
    private char[][] map;
    private int sizeX;
    private int sizeY;
    private int PLocationX;
    private int PLocationY;
    private ArrayList<Vendor> ListVendor;
    //method
    //konstruktor
    public MapTranslator(String namafile){
        sizeX = 0;
        sizeY = 0;
        PLocationX = -999;
        PLocationY = -999;
        //menyusun vendor (masih dummy tanpa file input)
        ArrayList<Integer> listtempA = new ArrayList<Integer>();
        listtempA.add(1);
        listtempA.add(2);
        listtempA.add(3);
        listtempA.add(5);
        Vendor A = new Vendor('A',listtempA);
        ArrayList<Integer> listtempB = new ArrayList<Integer>();
        listtempB.add(1);
        listtempB.add(2);
        Vendor B = new Vendor('B',listtempB);
        ArrayList<Integer> listtempC = new ArrayList<Integer>();
        listtempC.add(4);
        Vendor C = new Vendor('C',listtempC);
        ArrayList<Integer> listtempD = new ArrayList<Integer>();
        listtempD.add(1);
        listtempD.add(3);
        Vendor D = new Vendor('D',listtempD);
        ListVendor = new ArrayList<Vendor>();
        ListVendor.add(A);
        ListVendor.add(B);
        ListVendor.add(C);
        ListVendor.add(D);
        //mencari panjang & lebar map
        try{
            Scanner scanner = new Scanner(new FileReader("src/pencarian/" + namafile));
            if(scanner.hasNextLine()){
                sizeX = Integer.parseInt(scanner.next());
                sizeY = Integer.parseInt(scanner.next());
            }
        }
        catch(FileNotFoundException e){
            System.out.println("File not found");
        }
        map = new char[sizeX][sizeY]; //konstruksi dimensi abtraksi map
        //isi map abstrak dengan data dari file input
        try{
            Scanner scanner = new Scanner(new FileReader("src/pencarian/" + namafile));
            scanner.nextLine();
            String line;
            while(scanner.hasNextLine()){  
                for(int j=0;j<=sizeY-1;j++){
                    line = scanner.nextLine();
                    for(int i=0;i<=sizeX-1;i++){
                        map[i][j] = line.charAt(i);
                        if(map[i][j] == 'P'){
                            PLocationX = i;
                            PLocationY = j;
                        }
                    }
                }
            }
        }
        catch(FileNotFoundException e){
            System.out.println("File not found");
        }
    }
    public char[][] getMap(){
        return map;
    }
    public Coordinat getPLocation(){
        Coordinat P = new Coordinat(PLocationX,PLocationY);
        return P;
    }
    public int getSizeX(){
        return sizeX;
    }
    public int getSizeY(){
        return sizeY;
    }
    public ArrayList<Vendor> getListVendor(){
        return ListVendor;
    }
    //memperlihatkan abstraksi map (console only)
    public void showMatrix(){
        for(int j=0;j<=sizeY-1;j++){
            for(int i=0;i<=sizeX-1;i++){
                System.out.print(map[i][j] + " ");
            }
            System.out.println();
        }
        System.out.println("sizeX = " + sizeX + ", sizeY = " + sizeY);
    }
}
